package com.swq.java.code.chapter14.code06;

public class Varable {
    public static int max(int... datas) throws Exception {  //datas为可变参数
        if (datas.length == 0)
            return -1;

        int result = 0;
        for (int a : datas)
            if (result < a) result = a;
        return result;
    }

    public static void main(String[] args) throws Exception {
        System.out.print(max(5) + ",");
        System.out.print(max(5, 8, 2, 4, 5) + ",");
        System.out.print(max(new int[]{4, 10, 6, 5}) + ",");
        System.out.print(max());  //调用max()方法时未传入任何参数
    }
}